package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.CarRenewalStatus;
import com.ygxsk.carhome.response.CarInsuranceBean;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.util.List;

public class CarInsuranceAdapter extends BaseQuickAdapter<CarInsuranceBean, BaseViewHolder> {

    public CarInsuranceAdapter(int layoutResId, @Nullable List<CarInsuranceBean> data) {
        super(layoutResId, data);

        addChildClickViewIds(R.id.textViewPersonPhoneValueInsurance, R.id.roundTextViewViewTakeOrderInsurance, R.id.roundTextViewViewCompleteOrderInsurance);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CarInsuranceBean carInsuranceBean) {

        if (carInsuranceBean != null) {

            //filldatas
            //联系人
            String name = carInsuranceBean.getName();

            //手机号
            String phone = carInsuranceBean.getPhone();

            //车牌号
            String licenseNo = carInsuranceBean.getLicenseNo();

            //时间内容
            String createTime = carInsuranceBean.getCreateTime();

            //身份证号
//            String idCard = carInsuranceBean.getIdCard();
            //车辆列表；
//            ArrayList<String> dataList = carInsuranceBean.getDataList();

            //状态的 数值格式
            String status = carInsuranceBean.getStatus();
            //状态值
            String statusString = carInsuranceBean.getStatusString();

            //行车本？

            //findView
            //姓名
            TextView textViewPersonValue = (TextView) baseViewHolder.getView(R.id.textViewPersonValueInsurance);
            //状态值内容
            TextView textViewPersonOrderState = (TextView) baseViewHolder.getView(R.id.textViewPersonOrderStateInsurance);
            //手机号
            TextView textViewPersonPhoneValue = (TextView) baseViewHolder.getView(R.id.textViewPersonPhoneValueInsurance);
            //车牌号
            TextView textViewCarNumberValue = (TextView) baseViewHolder.getView(R.id.textViewCarNumberValueInsurance);
            //创建时间
            TextView textViewCreateTimeInsurance = (TextView) baseViewHolder.getView(R.id.textViewCreateTimeInsurance);

            //外侧包裹两个按钮的布局
            RelativeLayout relativeLayoutTwoButton = (RelativeLayout) baseViewHolder.getView(R.id.relativeLayoutTwoButtonInsurance);
            //接单 按钮
            RoundTextView roundTextViewViewTakeOrder = (RoundTextView) baseViewHolder.getView(R.id.roundTextViewViewTakeOrderInsurance);
            //完成 按钮
            RoundTextView roundTextViewViewCompleteOrder = (RoundTextView) baseViewHolder.getView(R.id.roundTextViewViewCompleteOrderInsurance);

            //身份证号
//            TextView textViewIdCardNumberValue = (TextView) baseViewHolder.getView(R.id.textViewIdCardNumberValueInsurance);
            //行车本
//            BGANinePhotoLayout npl_item_moment_photos_renewal = (BGANinePhotoLayout) baseViewHolder.getView(R.id.npl_item_moment_photos_renewal);

            CommUtils.setText(textViewPersonValue, name);
            //状态值内容
            CommUtils.setText(textViewPersonOrderState, statusString);

//          CommUtils.setText(textViewPersonPhoneValue, phone);
            CommUtils.setText(textViewPersonPhoneValue, StringCodeUtils.mobileEncrypt(phone));

            CommUtils.setText(textViewCarNumberValue, licenseNo);
            CommUtils.setText(textViewCreateTimeInsurance, createTime);

            //status  0未接单  1已接单   2已完成
//            public enum CarRenewalStatus {
//            status  0未接单  1已接单   2已完成
//                    STATUS_NOT_TAKEORDER("0", "未接单"),
//                    STATUS_HAS_TAKEORDER("1", "已接单"),
//                    STATUS_HAS_COMPLETE("2", "已完成");

            if (TextUtils.equals(status, CarRenewalStatus.STATUS_NOT_TAKEORDER.getIndex())) {

                CommUtils.setViewVisible(relativeLayoutTwoButton);

                //接单 按钮 展示
                CommUtils.setViewVisible(roundTextViewViewTakeOrder);
                //完成 按钮  隐藏
                CommUtils.setViewGone(roundTextViewViewCompleteOrder);


            } else if (TextUtils.equals(status, CarRenewalStatus.STATUS_HAS_TAKEORDER.getIndex())) {

                CommUtils.setViewVisible(relativeLayoutTwoButton);

                //接单 按钮 展示
                CommUtils.setViewGone(roundTextViewViewTakeOrder);
                //完成 按钮  隐藏
                CommUtils.setViewVisible(roundTextViewViewCompleteOrder);

            } else if (TextUtils.equals(status, CarRenewalStatus.STATUS_HAS_COMPLETE.getIndex())) {

                CommUtils.setViewGone(relativeLayoutTwoButton);

                //
            }


        }

    }
}
